package com.hnichr.ump.salon.controller;


import com.hnichr.ump.common.salon.entity.SalonInfo;
import com.hnichr.ump.common.salon.service.SalonInfoService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salon/info/v1/")
@Tag(name = "SalonInfoController", description = "沙龙信息维护接口")
public class SalonInfoController {

    @Autowired
    private SalonInfoService salonInfoService;

    @GetMapping("list")
    @Operation(summary = "沙龙信息列表", description = "沙龙信息列表（无分页）", method = "GET")
    public Result<List<SalonInfo>> list(@Parameter(description="查询参数") Criteria criteria){
        List<SalonInfo> list = salonInfoService.list(criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "沙龙信息列表", description = "沙龙信息列表（分页）", method = "GET")
    public Result<Page<SalonInfo>> page(@Parameter(description="查询参数")  Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo){
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<SalonInfo> list = salonInfoService.listPage(page, criteria);
        return Result.OK(list);
    }

    @GetMapping("list/{id}")
    @Operation(summary = "根据ID获取沙龙信息", description = "根据ID获取沙龙信息", method = "GET")
    public Result<SalonInfo> getById(@Parameter(description="ID") @PathVariable(name = "id", required = true) String id) {
        SalonInfo salonInfo = salonInfoService.getById(id);
        return Result.OK(salonInfo);
    }

    @PostMapping("add")
    @Operation(summary = "新增沙龙信息", description = "新增沙龙信息", method = "POST")
    public Result<SalonInfo> add(@RequestBody SalonInfo salonInfo) {
        salonInfoService.add(salonInfo);
        return Result.OK(salonInfo);
    }

    @PutMapping("edit")
    @Operation(summary = "编辑沙龙信息", description = "编辑沙龙信息", method = "PUT")
    public Result<SalonInfo> edit(@RequestBody SalonInfo salonInfo) {
        salonInfoService.update(salonInfo);
        return Result.OK(salonInfo);
    }
    @DeleteMapping("remove/{ids}")
    @Operation(summary = "根据id删除沙龙信息", description = "根据id删除沙龙信息", method = "DELETE")
    public Result<SalonInfo> remove(@PathVariable(name = "ids", required = true) String ids) {
        salonInfoService.remove(ids);
        return Result.OK();
    }
}
